package com.tradeplus.consumer;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.tradeplus.consumer.service.ConsumerService;
import com.tradeplus.security.model.User;
import com.tradeplus.security.service.UserDetailsService;
import com.tradeplus.util.JSONView;
import com.tradeplus.util.TPLController;

public class ConsumerController extends TPLController {
	
	private UserDetailsService userDetailsService;
	private ConsumerService consumerService;
	
	public void setUserDetailsService(UserDetailsService userDetailsService) {
		this.userDetailsService = userDetailsService;
	}

	public void setConsumerService(ConsumerService consumerService) {
		this.consumerService = consumerService;
	}




	public ModelAndView InserUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
		request.getParameter("password");
		User user = new User();
		user.setUsername(request.getParameter("username"));
		user.setEncryptPassword(request.getParameter("username"),request.getParameter("password"));
		userDetailsService.save(user);
		
		HashMap userMap = new HashMap();
		userMap.put("user", "new");
		
		return new ModelAndView(new JSONView(), userMap);
		
	}
	
	
	/**
     * Load Login view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    public ModelAndView Login(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return new ModelAndView("/consumer/login",new HashMap());
    }
    
    /**
     * Load profile view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Profile(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap profileMap = new HashMap();
    	profileMap.put("PageTitle", "Profile");
    	profileMap.put("PageLink", "profile");
    	
        return new ModelAndView("/consumer/profile",profileMap);
    }
    
    /**
     * Load Home view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Dashboard(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap dashboardMap = new HashMap();
    	dashboardMap.put("PageTitle", "Dashboard");
    	dashboardMap.put("PageLink", "dashboard");
    	
        return new ModelAndView("/consumer/dashboard",dashboardMap);
    }
    
    /**
     * Load Profile Details view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView ProfileDetails(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap profileDetailsMap = new HashMap();
    	profileDetailsMap.put("PageTitle", "profile");
    	profileDetailsMap.put("PageLink", "profile");
    	
        return new ModelAndView("/consumer/profile_details",profileDetailsMap);
    }
    
    /**
     * Load Details view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Details(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap detailsMap = new HashMap();
    	detailsMap.put("PageTitle", "Details");
    	detailsMap.put("PageLink", "profile");
    	detailsMap.put("Country", consumerService.loadCountry());
    	detailsMap.put("State", consumerService.loadState());
    	detailsMap.put("City", consumerService.loadCity());
    	
        return new ModelAndView("/consumer/details", detailsMap);
    }
    
    /**
     * Load Password view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Password(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap passwordMap = new HashMap();
    	passwordMap.put("PageTitle", "Password");
    	passwordMap.put("PageLink", "profile");
    	
        return new ModelAndView("/consumer/password",passwordMap);
    }
    
    /**
     * Load Account Password view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView AccountPassword(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap accountPasswordMap = new HashMap();
    	accountPasswordMap.put("PageTitle", "Account Password");
    	accountPasswordMap.put("PageLink", "profile");
    	
        return new ModelAndView("/consumer/account_password",accountPasswordMap);
    }
    
    /**
     * Load Transaction Password view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView TransactionPassword(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap transactionPasswordMap = new HashMap();
    	transactionPasswordMap.put("PageTitle", "Transaction Password");
    	transactionPasswordMap.put("PageLink", "profile");
    	
        return new ModelAndView("/consumer/transaction_password",transactionPasswordMap);
    }
    
    /**
     * Load Account Details view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView AccountDetails(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap accountDetailsMap = new HashMap();
    	accountDetailsMap.put("PageTitle", "Account Details");
    	accountDetailsMap.put("PageLink", "account");
    	
        return new ModelAndView("/consumer/account_details",accountDetailsMap);
    }
    
    /**
     * Load Wallet Information view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView WalletInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap walletInfoMap = new HashMap();
    	walletInfoMap.put("PageTitle", "E-Wallet Information");
    	walletInfoMap.put("PageLink", "account");
    	
        return new ModelAndView("/consumer/wallet_info",walletInfoMap);
    }
    
    
    /**
     * Load Board Wallet Information view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView BoardWallet(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap boardWalletMap = new HashMap();
    	boardWalletMap.put("PageTitle", "Board E-Wallet Information");
    	boardWalletMap.put("PageLink", "account");
    	
        return new ModelAndView("/consumer/board_wallet",boardWalletMap);
    }
    
    /**
     * Load Investment Wallet Information view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView InvestmentWallet(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap investmentWalletMap = new HashMap();
    	investmentWalletMap.put("PageTitle", "Investment E-Wallet Information");
    	investmentWalletMap.put("PageLink", "account");
    	
        return new ModelAndView("/consumer/investment_wallet",investmentWalletMap);
    }
    
    /**
     * Load Cash Requisition view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView CashRequisition(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap cashRequisitionMap = new HashMap();
    	cashRequisitionMap.put("PageTitle", "Cash Requisition");
    	cashRequisitionMap.put("PageLink", "account");
    	
        return new ModelAndView("/consumer/cash_requisition",cashRequisitionMap);
    }
    
    
    /**
     * Load Send PayOrder view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView SendToPayOrder(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap sendToPayOrderMap = new HashMap();
    	sendToPayOrderMap.put("PageTitle", "Send To Payorder");
    	sendToPayOrderMap.put("PageLink", "account");
    	
        return new ModelAndView("/consumer/send_to_payorder",sendToPayOrderMap);
    }
    
    /**
     * Load Send liberty reserve view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView SendToLibertyReserve(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap sendToLibertyReserveMap = new HashMap();
    	sendToLibertyReserveMap.put("PageTitle", "Send To Liberty Reserve Account");
    	sendToLibertyReserveMap.put("PageLink", "account");
    	
    	return new ModelAndView("/consumer/send_to_liberty_reserve",sendToLibertyReserveMap);
    }
    
    /**
     * Load genealogy view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Genealogy(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap genealogyMap = new HashMap();
    	genealogyMap.put("PageTitle", " Genealogy ");
    	genealogyMap.put("PageLink", "genealogy");
    	
        return new ModelAndView("/consumer/genealogy", genealogyMap);
    }
    
    /**
     * Load genealogy summary view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView GenealogySummary(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap genealogySummaryMap = new HashMap();
    	genealogySummaryMap.put("PageTitle", "Genealogy Summary");
    	genealogySummaryMap.put("PageLink", "genealogy");
    	
    	return new ModelAndView("/consumer/genealogy_summary",genealogySummaryMap);
    }
    
    /**
     * Load view board summary view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView ViewBoard(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap viewBoardMap = new HashMap();
    	viewBoardMap.put("PageTitle", "View Board");
    	viewBoardMap.put("PageLink", "genealogy");
    	
        return new ModelAndView("/consumer/view_board",viewBoardMap);
    }
    
    /**
     * Load search downline view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView SearchDownline(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap searchDownlineMap = new HashMap();
    	searchDownlineMap.put("PageTitle", "Search Downline");
    	searchDownlineMap.put("PageLink", "genealogy");
    	
        return new ModelAndView("/consumer/search_downline",searchDownlineMap);
    }
    
    /**
     * Load view downline view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView ViewDownline(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap viewDownlineMap = new HashMap();
    	viewDownlineMap.put("PageTitle", "View Downline");
    	viewDownlineMap.put("PageLink", "genealogy");
    	
        return new ModelAndView("/consumer/view_downline",viewDownlineMap);
    }
    
    /**
     * Load incentives view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Incentives(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap incentivesMap = new HashMap();
    	incentivesMap.put("PageTitle", "Incentives");
    	incentivesMap.put("PageLink", "genealogy");
    	
        return new ModelAndView("/consumer/incentives",incentivesMap);
    }
    
    /**
     * Load forwarding view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Forwarding(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap forwardingMap = new HashMap();
    	forwardingMap.put("PageTitle", "Forwarding");
    	forwardingMap.put("PageLink", "genealogy");
    	
        return new ModelAndView("/consumer/forwarding",forwardingMap);
    }
    
    /**
     * Load commission view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Commission(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap commissionMap = new HashMap();
    	commissionMap.put("PageTitle", "Commission");
    	commissionMap.put("PageLink", "commission");
    	
        return new ModelAndView("/consumer/commission",commissionMap);
    }
    
    /**
     * Load commission view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Miscellaneous(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap miscellaneousMap = new HashMap();
    	miscellaneousMap.put("PageTitle", "Miscellaneous");
    	miscellaneousMap.put("PageLink", "miscellaneous");
    	
        return new ModelAndView("/consumer/miscellaneous",miscellaneousMap);
    }
    
    /**
     * Load support view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView Support(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap supportMap = new HashMap();
    	supportMap.put("PageTitle", "Support");
    	supportMap.put("PageLink", "support");
    	
        return new ModelAndView("/consumer/support",supportMap);
    }
    
    /**
     * Load support view in the ftl
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception 
     */
    @SuppressWarnings("unchecked")
    public ModelAndView loadCountry(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	HashMap countryMap = new HashMap();
    	countryMap.put("Country", consumerService.loadCountry());
    	
    	return new ModelAndView(new JSONView(),countryMap);
    }

}
